<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Zans extends Modules_Controller
{

    function __construct()
    {
        parent::__construct();
    }

    public function index($cid=false,$page=1)
    {
        // 栏目路径
        $vdata['cpath']= $this->mcol->get_path_more($this->cid);
        $vdata['cchildren'] = $this->mcol->get_cols($this->cid);
        $title = $this->mcol->get_one($this->cid,"title");
        $vdata['title'] = $title['title'];

        $limit = $this->page_limit;
        $this->input->get('limit',TRUE) and is_numeric($this->input->get('limit')) AND $limit = $this->input->get('limit');

        $cid=0;
        $where1 = array('a.cid'=>$cid,"a.ccid"=>$this->ccid);
        $arr = array();
        if (isset($_GET['tid'])) {
            $arr['tid'] = $_GET['tid'];
        }
        $where = array_merge($arr,$where1);
        $this->db->select('a.id,a.created,a.money,a.tid,b.uname');
        $this->db->from('boc_text_zan as a');
        $this->db->join('boc_account as b','a.uid=b.id','left');
        $this->db->where($where);
        $this->db->order_by('a.created','desc');
        $this->db->limit($limit,$limit*($page-1));
        $vdata['list']=$this->db->get()->result_array();
        //分页
        $this->db->select('a.id,a.created,a.money,a.tid,b.uname');
        $this->db->from('boc_text_zan as a');
        $this->db->join('boc_account as b','a.uid=b.id','left');
        $this->db->where($where);
        $all = $this->db->get()->result_array();
        $count = count($all);
        $vdata['pages'] = $this->_pages(site_url($this->class.'/index/'.$this->cid.'/'),$limit,$count,4);
        $this->_display($vdata);
    }

    protected function _pages($url,$per_page=-1,$count=0,$uri=3){
        if (!$per_page < 0) {
            $per_page = $this->page_limit;
        }
        $this->load->library('pagination');
        $this->pagination->initialize(page_config($per_page,$count,$url,$uri));
        return $this->pagination->create_links();
    }

}
